﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Service
{

    /// <summary>
    /// 封装  JobInstance实例 
    /// </summary>
    public sealed class JobInstance : SoftObject
    {


        /// <summary>
        /// job的名称
        /// </summary>
        public string Name { get; private set; } = string.Empty;


        /// <summary>
        /// 是否是默认的job实例名 【job的名称为空】
        /// </summary>
        public bool IsDefaultInstaceName
        {
            get
            {
                return this.Name == string.Empty;
            }
        }


        /// <summary>
        /// job运行的方法
        /// </summary>
        public JobServiceMode Mode { get; private set; }


        /// <summary>
        /// jobService job服务启动的方式
        /// </summary>
        public JobServiceStartType StartType { get; set; }


        /// <summary>
        /// job 实例的类型
        /// </summary>
        public Type InstanceType { get; private set; }


        /// <summary>
        /// 执行方法调用时触发的事件
        /// </summary>
        public ExecuteMethodCallInstructionEventHandle ExecuteMethodHandle { get; private set; }


        /// <summary>
        /// job的父类
        /// </summary>
        public BaseJob Instance { get; set; }


        /// <summary>
        /// 封装job实例
        /// </summary>
        /// <param name="instanceType"></param>
        /// <param name="mode"></param>
        /// <param name="executeMethodHandle"></param>
        /// <param name="instanceName"></param>
        public JobInstance(Type instanceType, JobServiceMode mode, ExecuteMethodCallInstructionEventHandle executeMethodHandle, string instanceName = null)
        {
            if (instanceType == null)
            {
                throw new ArgumentNullException("instanceType");
            }
            this.InstanceType = instanceType;
            this.Mode = mode;
            if (executeMethodHandle == null)
            {
                throw new ArgumentNullException("executeMethodHandle");
            }
            this.ExecuteMethodHandle = executeMethodHandle;
            this.Name = (instanceName ?? string.Empty).Trim().ToUpper();
        }


    }
}
